home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / fddicmd / fddicmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  8.6 KB  |  296 lines

  1. /* 
  2.  * fddicmd.c --
  3.  *
  4.  *    Program for dealing with the DEC FDDI adapter.
  5.  *
  6.  * Copyright 1992 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/cmds/fddicmd/RCS/fddicmd.c,v 1.4 92/05/29 11:13:57 voelker Exp Locker: jhh $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include "sprite.h"
  21. #include "option.h"
  22. #include <stdio.h>
  23. #include <sys/file.h>
  24. #include <fs.h>
  25. #include <kernel/netTypes.h>
  26. #include <net.h>
  27. #include <netFDDI.h>
  28. #include <dev/fddi.h>
  29. #include <status.h>
  30. #include <fmt.h>
  31. #include <time.h>
  32.  
  33. char    *deviceName = "/dev/fddi";
  34. char    *infileName = NULL;
  35. Boolean reset = FALSE;
  36. Boolean halt = FALSE;
  37. Boolean debug = FALSE;
  38. Boolean readDevice = FALSE;
  39. Boolean printReg = FALSE;
  40. Boolean printErrLog = FALSE;
  41. Boolean flush = FALSE;
  42. Boolean linkAddr = FALSE;
  43. Boolean syslog = FALSE;
  44. Boolean source = FALSE;
  45. Boolean getStats = FALSE;
  46. Boolean multipleWrite = FALSE;
  47. Boolean getStatus = FALSE;
  48.  
  49. int     echo = NIL;
  50. int     packetSize = 1024;
  51. int     repeat = 100;
  52.  
  53. Option optionArray[] = {
  54.     {OPT_DOC, NULL, NULL, "Usage: fddicmd [options]"},
  55.     {OPT_TRUE, "reset", (Address) &reset,
  56.     "Reset the adapter."},
  57.     {OPT_TRUE, "halt", (Address) &halt,
  58.     "Halt the adapter."},
  59.     {OPT_TRUE, "flush", (Address) &flush,
  60.     "Flush the transmit queue."},
  61.     {OPT_TRUE, "addr", (Address) &linkAddr,
  62.     "Link address of the adapter."},
  63.     {OPT_TRUE, "debug", (Address) &debug,
  64.     "Toggle the adapter debugging information."},
  65.     {OPT_TRUE, "stats", (Address) &getStats,
  66.     "Print adapter statistics."},
  67.     {OPT_INT, "echo", (Address) &echo,
  68.     "Echo the designated RPC server (by SpriteID)"},
  69.     {OPT_INT, "size", (Address) &packetSize,
  70.     "Size of packet to use."},
  71.     {OPT_INT, "repeat", (Address) &repeat,
  72.     "Number of times to echo."},
  73.     {OPT_TRUE, "syslog", (Address) &syslog,
  74.      "Print output onto the syslog intead of stdout."},
  75.     {OPT_TRUE, "reg", (Address) &printReg,
  76.     "Print the values in the adapter registers."},
  77.     {OPT_TRUE, "status", (Address) &getStatus,
  78.     "Print the status of the FDDI interface."},
  79.     {OPT_TRUE, "errlog", (Address) &printErrLog,
  80.     "Print the useful information in the adapter error log."},
  81.     {OPT_DOC, "\0", (Address)NULL, "These are the internal and external error codes that the adapter writes"},
  82.     {OPT_DOC, "\0", (Address)NULL, "as it halts.  They should be zero for normal operation."},
  83. };
  84.  
  85. int numOptions = sizeof(optionArray) / sizeof(Option);
  86.  
  87. #define CheckStatus(status) \
  88.     if (status != SUCCESS) { \
  89.     printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); \
  90.     }
  91.  
  92.  
  93. /*
  94.  *----------------------------------------------------------------------
  95.  *
  96.  * main --
  97.  *
  98.  *    Parse the arguments and execute the command given.  The
  99.  *      commands are fairly simple...most of the work is done at
  100.  *      the driver level.
  101.  *
  102.  * Results:
  103.  *    None.
  104.  *
  105.  * Side effects:
  106.  *    None.
  107.  *
  108.  *----------------------------------------------------------------------
  109.  */
  110. int
  111. main(argc, argv)
  112.     int argc;
  113.     char *argv[];
  114. {
  115.     int                argsLeft;
  116.     int                fd;
  117.     ReturnStatus       status;
  118.     int                size;
  119.  
  120.     argsLeft = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  121.     if (argsLeft > 2) {
  122.     Opt_PrintUsage(argv[0], optionArray, numOptions);
  123.     exit(1);
  124.     }
  125.     fd = open(deviceName, O_RDONLY, 0);
  126.     if (fd < 0) {
  127.     printf("Can't open device \"%s\"\n", deviceName);
  128.     perror("");
  129.     exit(1);
  130.     }
  131.     /*
  132.      * Turns on debugging output to the syslog.  This really slows
  133.      * down the adapter because it has to print all of these
  134.      * messages.
  135.      */
  136.     if (debug) {
  137.     status = Fs_IOControl(fd, IOC_FDDI_DEBUG, 0, NULL, 0, NULL);
  138.     CheckStatus(status);
  139.     exit(0);
  140.     }
  141.     /*
  142.      * Print out the contents of the adapter registers.  It doesn't
  143.      * help much, unless you have the manual there to look at.
  144.      */
  145.     if (printReg) {
  146.     Dev_FDDIRegContents contents;
  147.     status = Fs_IOControl(fd, IOC_FDDI_REG_CONTENTS, 0, NULL, 
  148.                   sizeof(Dev_FDDIRegContents), &contents);
  149.     if (status != SUCCESS) { 
  150.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  151.     } else {
  152.         printf("Reset: 0x%x\tCtrlA: 0x%x\tCtrlB: 0x%x\n", 
  153.            contents.regReset, contents.regCtrlA, contents.regCtrlB);
  154.         printf("Status: 0x%x\tEvent: 0x%x\tMask: 0x%x\n", 
  155.            contents.regStatus, contents.regEvent, contents.regMask);
  156.     }
  157.     exit(0);
  158.     }
  159.     /*
  160.      * Print out the status of the interface.
  161.      */
  162.     if (getStatus) {
  163.     Dev_FDDIRegContents contents;
  164.     static char *msgs[] = {"Resetting", "Unitialized", "Initialized",
  165.         "Running", "Maintenance", "Halted", "Undefined 1", "Undefined 2"};
  166.     status = Fs_IOControl(fd, IOC_FDDI_REG_CONTENTS, 0, NULL, 
  167.                   sizeof(Dev_FDDIRegContents), &contents);
  168.     if (status != SUCCESS) { 
  169.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  170.     } else {
  171.         printf("Status: %-16s Link: %-16s\n", 
  172.         msgs[(contents.regStatus & 0x0700) >> 8], 
  173.         (contents.regStatus & 0x800) ? "Available" : "Unavailable");
  174.     }
  175.     exit(0);
  176.     }
  177.     /*
  178.      * Prints out the external and internal error values that
  179.      * the adapter write's into its error log as it halts.
  180.      */
  181.     if (printErrLog) {
  182.     Dev_FDDIErrLog errLog;
  183.  
  184.     status = Fs_IOControl(fd, IOC_FDDI_ERR_LOG, 0, NULL, 
  185.                   sizeof(Dev_FDDIErrLog), &errLog);
  186.     if (status != SUCCESS) { 
  187.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  188.     } else {
  189.         printf("External: 0x%x\tInternal: 0x%x\n",
  190.            errLog.external, errLog.internal);
  191.     }
  192.     exit(0);
  193.     }
  194.     /*
  195.      * Flushes the driver's queue of pending writes.
  196.      */
  197.     if (flush) {
  198.     status = Fs_IOControl(fd, IOC_FDDI_FLUSH_XMT_Q, 0, NULL, 0, NULL);
  199.     CheckStatus(status);
  200.     exit(0);
  201.     }
  202.     /*
  203.      * Print out the network address of the adapter.
  204.      */
  205.     if (linkAddr) {
  206.     Dev_FDDILinkAddr fddiInfo;
  207.     char             buffer[32];
  208.  
  209.     status = Fs_IOControl(fd, IOC_FDDI_ADDRESS, 0, NULL, 
  210.                   sizeof(Dev_FDDILinkAddr), &fddiInfo);
  211.     if (status != SUCCESS) {
  212.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  213.     } else {
  214.         (void)Net_EtherAddrToString(&fddiInfo.source, buffer);
  215.         printf("Adapter FDDI address: %s\n", buffer);
  216.     }
  217.     exit(0);
  218.     }
  219.     /*
  220.      * Print out adapter statistics.
  221.      */
  222.     if (getStats) {
  223.     Dev_FDDIStats stats;
  224.     int           i;
  225.  
  226.     status = Fs_IOControl(fd, IOC_FDDI_STATS, 0, NULL,
  227.                   sizeof(Dev_FDDIStats), &stats);
  228.     if (status != SUCCESS) {
  229.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  230.     } else {
  231.         printf("Packets sent:\t%9d\n", stats.packetsSent);
  232.         printf("Packets queued:\t%9d\n", stats.packetsQueued);
  233.         printf("Packets dropped:\t%9d\n", stats.xmtPacketsDropped);
  234.         printf("Bytes sent  :\t%9d\n", stats.bytesSent);
  235.         printf("Packets received:\t%9d\n", 
  236.            stats.packetsReceived);
  237.         printf("Bytes received  :\t%9d\n", 
  238.            stats.bytesReceived);
  239.         for (i = 0; i < NET_FDDI_STATS_RCV_REAPED; i++) {
  240.         printf("RCV reaped = [%d]:\t%9d\n", i + 1, 
  241.                stats.receiveReaped[i]);
  242.         }
  243.         for (i = 0; i < NET_FDDI_STATS_HISTO_NUM; i++) {
  244.         printf("RCV packet size [%d-%d]:\t%9d\nXMT packet size [%d-%d]:\t%9d\n",
  245.                i * NET_FDDI_STATS_HISTO_SIZE,
  246.                ((i + 1) * NET_FDDI_STATS_HISTO_SIZE) - 1,
  247.                stats.receiveHistogram[i],
  248.                i * NET_FDDI_STATS_HISTO_SIZE,
  249.                ((i + 1) * NET_FDDI_STATS_HISTO_SIZE) - 1,
  250.                stats.transmitHistogram[i]);
  251.         }
  252.            
  253.     }
  254.     exit(0);
  255.     }
  256.     /*
  257.      * Do an RPC Echo.
  258.      */
  259.     if (echo != NIL) {
  260.     Dev_FDDIRpcEcho       rpcEcho;
  261.     Dev_FDDIRpcEchoReturn rpcReturn;
  262.  
  263.     rpcEcho.serverID = echo;
  264.     rpcEcho.packetSize = packetSize;
  265.     rpcEcho.numEchoes = repeat;
  266.     rpcEcho.printSyslog = syslog;
  267.     status = Fs_IOControl(fd, IOC_FDDI_RPC_ECHO, sizeof(Dev_FDDIRpcEcho),
  268.                   &rpcEcho, sizeof(Dev_FDDIRpcEchoReturn),
  269.                   &rpcReturn);
  270.     if (status != SUCCESS) {
  271.         printf(stderr, "fddicmd: Fs_IOControl return 0x%x\n", status); 
  272.         exit(1);
  273.     }
  274.     printf("Time per RPC (size %d) %d.%06d\n", packetSize,
  275.            rpcReturn.rpcTime.seconds, rpcReturn.rpcTime.microseconds);
  276.     exit(0);
  277.     }
  278.     /*
  279.      * Halt the adapter.
  280.      */
  281.     if (halt) {
  282.     status = Fs_IOControl(fd, IOC_FDDI_HALT, 0, NULL, 0, NULL);
  283.     CheckStatus(status);
  284.     exit(0);
  285.     }
  286.     /*
  287.      * Reset the adapter.
  288.      */
  289.     if (reset) {
  290.     status = Fs_IOControl(fd, IOC_FDDI_RESET, 0, NULL, 0, NULL);
  291.     CheckStatus(status);
  292.     exit(0);
  293.     }
  294. }
  295.  
  296.